<template>
  <div class="searcha">
    <!-- 搜索input -->
    <div class="se_input">
      <div>
        <div class="se_div">
          <img
            src="https://o6wndwjxn.qnssl.com/search.svg"
            alt=""
          >
          <input
            type="text"
            value=""
            placeholder="搜索老师/课程"
            v-model="se_input"
          />
        </div>
      </div>
      <div @click="se_submit">搜索</div>
    </div>
    <div style="height: 40px;"></div>
    <!-- 搜索历史 -->
    <div
      class="se_Historical"
      v-show="se_Historical_status"
    >
      搜索历史
      <img
        src="https://o6wndwjxn.qnssl.com/%E5%88%A0%E9%99%A4@2x.png"
        alt=""
        @click="Historical_close"
      >
    </div>
    <div
      class="se_Historical_list"
      v-show="se_Historical_status"
    >
      <div
        v-for="(item,index) in se_Historical"
        :key='index'
        @click="se_click_sub(index)"
      >{{item}}</div>
    </div>
    <!-- 名师推荐 -->
    <div class="se_teacher">名师推荐</div>
    <div class="se_teacher_list">
      <div
        class="se_tea_box"
        v-for="(item,index) in se_teacher"
        :key='index'
        @click="se_tea_click(item.lecturer_id)"
      >

        <img
          v-if='item.img'
          :src="item.img"
          alt=""
        >
        <div v-else>
          <span>暂无</span>
          <span>头像</span>
        </div>

        <div>{{item.name}}</div>
        <div v-if="item.label !== null">{{item.label}}</div>
				<div v-else>&nbsp;</div>
      </div>
      <div
        class="se_huanyihuan"
        @click="getSe_Teacher"
      >
        换一换
        <img
          src="http://o6wndwjxn.qnssl.com/c91ec201903281349332973.png"
          alt=""
        >
      </div>
    </div>
    <!-- 人气推荐 -->
    <div class="se_Popularity">猜你喜欢</div>

    <div class="se_Popularity_list">
      <!-- <div class="se_Popularity_box" v-for="(item,index) in se_Popularity" :key='index' @click="se_pop_click(item.curriculum_id)">
				<img :src="item.cover" alt="">
				<div>{{item.title}}</div>
				<div>共计{{item.count}}课节 | {{item.snumber}}人已学</div>
				<div>¥{{item.preferential_money}}<span>¥{{item.money}}</span></div>
			</div> -->
      <Recommend :type='Recommend_list'></Recommend>
      <!-- <div
        class="se_huanyihuan"
        @click="getRecommend"
      >
        换一换
        <img
          src="http://o6wndwjxn.qnssl.com/c91ec201903281349332973.png"
          alt=""
        >
      </div> -->
    </div>

  </div>
</template>

<script>
import axios from 'axios'
import Recommend from '@/components/curriculum/Recommend.vue'
import {
  mapState
} from 'vuex'
import {
  search_popularity
} from '@/api/co_audio'
import {
  searchHistory,
  searchList,
  searchPopularity
} from '@/api/search'
export default {
  components: {
    Recommend
  },
  data () {
    return {
      se_Historical_status: false,
      se_input: '',
      se_Historical: [],
      se_teacher: [],
      se_Popularity: [],
      Recommend_list: []
    }
  },
  computed: {
    ...mapState({
      app_id: state => state.app_id,
      user_id: state => state.member_id
    })
  },
  created () {
    this.getSe_History()
    this.getSe_Teacher()
    this.getRecommend()
  },
  methods: {
    getRecommend () {
      let requery = {
        app_id: this.app_id
      }
      search_popularity(requery).then(res => {
        let { code, data } = res.data
        if (code == 200) {
          // console.log('猜你喜欢',data)
          this.Recommend_list = data
        }
      })
    },
    se_pop_click (e) {
      this.$router.push({
        path: '/coursedetails',
        query: {
          curriculumId: e
        }
      })
    },
    se_tea_click (e) {
      this.$router.push({
        path: '/teacher',
        query: {
          lecturer_id: e
        }
      })
    },
    getSe_Teacher () {
      let requery = {
        app_id: this.$store.state.app_id
      }
      searchList(requery).then(res => {
        let {
          code,
          data
        } = res.data
        console.log('讲师详情,search_list', data)
        if (code == 200) {
          this.se_teacher = data
        }
      })
    },
    getSe_Curriculum () {
      let requery = {
        app_id: this.$store.state.app_id
      }
      searchPopularity(requery).then(res => {
        let {
          code,
          data
        } = res.data
        if (code == 200) {
          this.se_Popularity = data
        }
      })
    },
    se_click_sub (e) {
      // console.log(e)
      this.$router.push({
        name: 'co_result',
        params: {
          input: this.se_Historical[e]
        }
      })
    },
    getSe_History () {
      let requery = {
        app_id: this.$store.state.app_id,
        user_id: this.$store.state.member_id
      }
      searchHistory(requery).then(res => {
        this.$store.commit('updateLoadingStatus', { isLoading: false })
        let {
          code,
          data
        } = res.data
        if (code == 200) {
          this.se_Historical = data
          this.se_Historical_status = true
        }
      })
    },
    se_submit () {
      if (this.se_input == '') return
      this.$router.push({
        name: 'co_result',
        params: {
          input: this.se_input
        }
      })
    },
    Historical_close () {
      let requery = {
        app_id: this.$store.state.app_id,
        user_id: this.$store.state.member_id
      }
      axios.post('http://www.ztwlxx.net/api/Chat/chat/solist_delete', requery).then(res => {
        let {
          code,
          data
        } = res.data
        if (code == 200) {
          this.se_Historical_status = false
        }
      })
    }
  }
}
</script>

<style>
.se_input {
  width: 100%;
  height: 50px;
  overflow: hidden;
  display: flex;
  position: fixed;
  left: 0;
  top: 0;
  background: white;
  z-index: 5;
}

.se_div > img {
  height: 20px;
  margin: 5px;
  margin-left: 10px;
}

.se_input {
  width: 100%;
  display: flex;
  padding: 0 5%;
}

.se_input > div:first-child {
  flex: 4;
}

.se_input > div:last-child {
  flex: 1;
  text-indent: 20px;
  text-align: center;
  line-height: 40px;
  font-size: 17px;
  color: #DA4131;
  padding-top: 5px;
}

.se_div {
  background: #f5f5f5;
  height: 30px;
  margin: 10px 0 5px 0;
  position: relative;
  border-radius: 15px;
}

.se_div > input {
  position: absolute;
  width: 100%;
  height: 100%;
  left: 0;
  top: 0;
  background: none;
  border: none;
  outline: none;
  text-indent: 40px;
  font-size: 15px;
}

.se_Historical,
.se_teacher,
.se_Popularity {
  width: 90%;
  margin: 0 5%;
  height: 40px;
  line-height: 40px;
  font-size: 15px;
  color: #1a1a1a;
  font-weight: bold;
  position: relative;
}

.se_Historical > img {
  position: absolute;
  right: 0;
  top: 12px;
  width: 16px;
}

.se_huanyihuan {
  width: 30%;
  box-sizing: border-box;
  text-indent: 20px;
  margin: 0 auto;
  height: 30px;
  background-color: #DA4131;
  line-height: 30px;
  font-size: 14px;
  color: #fff;
  font-weight: bold;
  position: relative;
  margin-top: 20px;
  border-radius: 15px;
}

.se_huanyihuan > img {
  width: 18px;
  height: 18px;
  position: absolute;
  left: 70%;
  top: 6px;
}

.se_Historical_list {
  width: 90%;
  margin: 0 5%;
}

.se_Historical_list > div {
  display: inline-block;
  padding: 8px 10px;
  font-size: 14px;
  color: #cccccc;
  background: #f5f5f5;
  margin: 2px 5px;
  border-radius: 500px;
}

.se_teacher_list {
  margin: 0 5%;
  width: 90%;
}

.se_tea_box {
  width: 30%;
  height: 135px;
  background: #f5f5f5;
  display: inline-block;
  overflow: hidden;
  text-align: center;
  border-radius: 4px;
}

.se_tea_box:nth-child(2) {
  margin: 0 5%;
}

.se_tea_box > img {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  margin-top: 15px;
}
.se_tea_box > div:nth-child(1) {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  margin: 0 auto;
  margin-top: 15px;
  background: white;
  text-align: center;
  font-size: 12px;
  color: #333333;
}
.se_tea_box > div:nth-child(1) span {
  display: block;
}
.se_tea_box > div:nth-child(1) span:nth-child(1) {
  height: 30px;
  line-height: 45px;
}
.se_tea_box > div:nth-child(1) span:nth-child(2) {
  height: 30px;
  line-height: 15px;
}

.se_tea_box > div:nth-child(2) {
  width: 80%;
  margin: 0 10%;
  font-size: 14px;
  color: #333;
  font-weight: bold;
  margin-top: 7px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.se_tea_box > div:nth-child(3) {
  font-size: 12px;
  color: #999999;
  overflow: hidden;
  margin-top: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.se_Popularity_list {
  width: 90%;
  margin: 0 5%;
  margin-bottom: 20px;
}

.se_Popularity_box {
  width: 50%;
  height: 170px;
  display: inline-block;
  margin: 5px 0;
}

.se_Popularity_box > img {
  height: 95px;
  width: 90%;
  margin: 0 5%;
  border-radius: 4px;
  object-fit: cover;
}

.se_Popularity_box > div {
  margin: 0 5%;
  width: 90%;
}

.se_Popularity_box > div:nth-child(2) {
  font-size: 15px;
  color: #1a1a1a;
  font-weight: bold;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 7px;
}

.se_Popularity_box > div:nth-child(3) {
  font-size: 12px;
  color: #999999;
  margin-top: 6px;
}

.se_Popularity_box > div:nth-child(4) {
  font-size: 14px;
  color: #fd5e5e;
  margin-top: 5px;
}

.se_Popularity_box > div:nth-child(4) span {
  font-size: 12px;
  color: #cccccc;
  position: relative;
  padding: 0 5px;
}

.se_Popularity_box > div:nth-child(4) span:after {
  position: absolute;
  content: "";
  left: 0;
  top: 50%;
  width: 100%;
  height: 1px;
  background: #cccccc;
}
</style>
